home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1996 #6 / Amiga Plus CD - 1996 - No. 06.iso / pd / programmierung / programmers / aura.a next >
Text File  |  1996-06-23  |  6KB  |  268 lines

  1. ; Use a 020-capable assembler for this!!
  2.         MC68020
  3.  
  4.         BSS
  5. ;first longword: data read pointer
  6. ;second longword: data end pointer (the last sample WORD to play)
  7. ;third longword: stereo offset pointer (# of bytes to add to get the right channel, 0 = mono)
  8. ;fourth longword: value to add (fixed rate only)
  9. ;fifth longword: remaining add offset (only lower word used)
  10. Auradata    ds.l    5
  11. owntimer    ds.w    1
  12. Aurachmode    ds.w    1
  13. Auraratemode    ds.w    1
  14. vbr_addr    ds.l    1
  15.         DATA
  16. Auraperlimit    dc.w    248
  17. Aurahandler    dc.l    AuraIntHandler
  18. playing_Aura    dc.w    0
  19.  
  20.         SECTION    "text",CODE
  21.         XDEF    _InitAura,_RemAura,_PlayAura,_StopAura,_SetAuraParams
  22.  
  23. ; For Barfly...
  24.         BOPT    ws-,w4-
  25.  
  26. ; _InitAura (void) -- initialize sample playback system
  27. ; returns: 0 = ok, nonzero = error
  28. _InitAura
  29.         tst.w    owntimer
  30.         bne.s    rm_rts
  31.         movem.l    a5/a6,-(sp)
  32.         move.w    #$400,$dff09a    ;audio ch #3 interrupt off
  33.         movea.l    4.w,a6
  34.         btst    #0,$129(a6)    ;test 68010+ of AttnFlags
  35.         beq.s    1$
  36.         lea    initaura_superv(pc),a5
  37.         jsr    -$1E(a6)    ;Supervisor()
  38.         move.l    a0,vbr_addr
  39. 1$        move.l    vbr_addr,a0
  40.         move.l    $70(a0),oldaudiointr    ;MODIFIED CODE... therefore...
  41.         jsr    -$27C(a6)        ;CacheClearU()
  42.         move.w    #1,owntimer
  43.         moveq    #0,d0
  44.         movem.l    (sp)+,a5/a6
  45.         rts
  46.  
  47. initaura_superv    movec    VBR,a0
  48.         rte
  49.  
  50. ;_RemAura (void) -- deallocate sample playback system resources
  51. _RemAura    tst.w    owntimer
  52.         beq.s    rm_rts
  53.         clr.w    owntimer
  54.         move.w    #$400,$dff09a    ;audio ch #3 interrupt off
  55.         move.l    vbr_addr,a0
  56.         move.l    oldaudiointr,$70(a0)
  57. rm_rts        rts
  58.  
  59. AuraSIntHandler    ;single channel playback
  60.         move.l    d0,-(sp)
  61.         move.w    $dff01e,d0
  62.         btst    #$A,d0        ;intr 3?
  63.         beq.w    jmpoldintr
  64.         move.l    a0,-(sp)
  65.         move.w    #$400,$dff09c
  66.         movea.l    Auradata,a0    ;addr...
  67.         move.w    (a0)+,$A20000    ;final...
  68.         move.w    #0,$dff0da
  69.         cmpa.l    Auradata+4,a0
  70.         bhi.s    Auraaudintr_end
  71.         move.l    a0,Auradata
  72.         move.l    (sp)+,a0
  73.         move.l    (sp)+,d0
  74.         rte
  75.  
  76. AuraIntHandler    ; plays through both channels
  77.         move.l    d0,-(sp)
  78.         move.w    $dff01e,d0
  79.         btst    #$A,d0        ;intr 3?
  80.         beq.s    jmpoldintr
  81.         move.l    a0,-(sp)
  82.         move.w    #$400,$dff09c
  83.         movea.l    Auradata,a0    ;addr...
  84.         move.w    (a0)+,$A20000    ;final...
  85.         move.l    Auradata+8,d0
  86.         move.w    -2(a0,d0.l),$A20002    ;stereo offset
  87.         move.w    #0,$dff0da
  88.         cmpa.l    Auradata+4,a0
  89.         bhi.s    Auraaudintr_end
  90.         move.l    a0,Auradata
  91.         move.l    (sp)+,a0
  92.         move.l    (sp)+,d0
  93.         rte
  94.  
  95. jmpoldintr    move.l    (sp)+,d0
  96.         dc.w    $4ef9
  97. oldaudiointr    dc.l    0
  98.  
  99. Auraaudintr_end_f
  100.         move.l    (sp)+,a1
  101. Auraaudintr_end    move.w    #$400,$dff09a
  102.         move.l    (sp)+,a0
  103.         move.l    (sp)+,d0
  104.         clr.b    playing_Aura
  105.         rte
  106.  
  107. AuraFIntHandler    ; plays through both channels, fixed output rate
  108.         move.l    d0,-(sp)
  109.         move.w    $dff01e,d0
  110.         btst    #$A,d0        ;intr 3?
  111.         beq.s    jmpoldintr
  112.         move.l    a0,-(sp)
  113.         move.l    a1,-(sp)
  114.         lea    Auradata,a1
  115.         move.w    #$400,$dff09c
  116.         movea.l    (a1),a0    ;addr...
  117.         move.w    (a0),$A20000    ;final...
  118.         move.l    8(a1),d0
  119.         move.w    0(a0,d0.l),$A20002 ;stereo offset (only mono (= 0) in V5.04 though)
  120.         moveq    #0,d0
  121.         move.w    d0,$dff0da
  122.         move.w    18(a1),d0    ;get remaining offset fraction (always < 1 [0x10000])
  123.         add.l    12(a1),d0    ;add rate value
  124.         swap    d0
  125.         adda.w    d0,a0        ;add to sample pointer
  126.         adda.w    d0,a0        ;twice, because we handle words!
  127.         swap    d0
  128.         move.w    d0,18(a1)    ;store current fraction...
  129.         cmpa.l    4(a1),a0
  130.         bhi.s    Auraaudintr_end_f
  131.         move.l    a0,(a1)
  132.         move.l    (sp)+,a1
  133.         move.l    (sp)+,a0
  134.         move.l    (sp)+,d0
  135.         rte
  136.  
  137. AuraSFIntHandler ; plays through single channel, fixed output rate
  138.         move.l    d0,-(sp)
  139.         move.w    $dff01e,d0
  140.         btst    #$A,d0        ;intr 3?
  141.         beq.w    jmpoldintr
  142.         move.l    a0,-(sp)
  143.         move.l    a1,-(sp)
  144.         lea    Auradata,a1
  145.         move.w    #$400,$dff09c
  146.         movea.l    (a1),a0    ;addr...
  147.         move.w    (a0),$A20000    ;final...
  148.         moveq    #0,d0
  149.         move.w    d0,$dff0da
  150.         move.w    18(a1),d0    ;get remaining offset fraction (always < 1 [0x10000])
  151.         add.l    12(a1),d0    ;add rate value
  152.         swap    d0
  153.         adda.w    d0,a0        ;add to sample pointer
  154.         adda.w    d0,a0        ;twice, because we handle words!
  155.         swap    d0
  156.         move.w    d0,18(a1)    ;store current fraction...
  157.         cmpa.l    4(a1),a0
  158.         bhi.w    Auraaudintr_end_f
  159.         move.l    a0,(a1)
  160.         move.l    (sp)+,a1
  161.         move.l    (sp)+,a0
  162.         move.l    (sp)+,d0
  163.         rte
  164.  
  165. ;_PlayAura -- Play Aura sample, input registers:
  166. ;    A0 = sample (struct Soitin *)
  167. ;    D0 = sample start offset (in WORDs)
  168. ;    D1 = sample period (UWORD)
  169. ;    D2 = sample end offset (i.e. offs to first word NOT to play) (0 = play until end)
  170.  
  171. _PlayAura    tst.w    owntimer
  172.         beq.w    playAura_exit
  173.         addq.l    #6,a0        ;skip header
  174.         add.l    d0,d0        ;words to bytes
  175.         add.l    a0,d0        ;d0 = sample start
  176.         move.l    d0,Auradata
  177.         btst    #5,-1(a0)    ;STEREO?
  178.         bne.s    pmd_stereo
  179.         moveq    #0,d0
  180.         bra.s    pmd_setstereo
  181. pmd_stereo    move.l    a0,d0
  182.         add.l    -6(a0),d0    ;add sample length...
  183. pmd_setstereo    move.l    d0,Auradata+8    ;store stereo offset
  184.         tst.l    d2
  185.         bne.s    pmd_givenend
  186.         move.l    -6(a0),d0    ;get length
  187.         bra.s    pmd_setend
  188. pmd_givenend    move.l    d2,d0
  189.         add.l    d0,d0
  190. pmd_setend    lea    -2(a0,d0.l),a0    ;ptr to last WORD
  191.         move.l    a0,Auradata+4
  192.         moveq    #0,d0
  193.         move.w    Auraperlimit,d0
  194.         tst.w    Auraratemode
  195.         bne.s    pmd_fixedrate
  196.         cmp.w    d0,d1
  197.         bhi.s    playAura_noovf
  198.         move.w    d0,d1
  199. playAura_noovf
  200.         lsr.w    #1,d1
  201.         movea.l    vbr_addr,a1
  202.         move.l    Aurahandler,$70(a1)
  203.         lea    $dff000,a0
  204.         move.w    #$8400,$9a(a0)    ;INTENA
  205.         move.w    #$0380,$9a(a0)
  206.         move.w    d1,$d6(a0)
  207.         move.w    #0,$d8(a0)
  208.         move.w    #$8400,$9c(a0)    ;INTREQ
  209.         st    playing_Aura
  210. playAura_exit    rts
  211.  
  212. ;    calculations for fixed playback rate...
  213. pmd_fixedrate
  214. ; multiply playback period by 16384...
  215.         swap    d0
  216.         lsr.l    #2,d0
  217. ; divide by note period...
  218.         divu    d1,d0
  219. ; clear upper word and multiply by 4
  220.         swap    d0
  221.         clr.w    d0
  222.         swap    d0
  223.         add.l    d0,d0
  224.         add.l    d0,d0
  225. ; now we have a rate multiplier...
  226.         move.l    d0,Auradata+12
  227.         clr.l    Auradata+16
  228.         move.w    Auraperlimit,d1
  229.         bra.s    playAura_noovf    ;set timer to run at maximum rate
  230.  
  231. ; _StopAura - may only trash A1!
  232. _StopAura    tst.w    owntimer
  233.         beq.s    stopAura_exit
  234.         clr.b    playing_Aura
  235.         move.w    #$400,$dff09a    ;audio 3 INTENA = 0
  236. stopAura_exit    rts
  237.  
  238. SetHandlerAddr    tst.w    Aurachmode
  239.         beq.s    sha_dual
  240.         tst.w    Auraratemode
  241.         beq.s    sha_s_var
  242.         lea    AuraSFIntHandler(pc),a0
  243.         bra.s    sha_set
  244. sha_s_var    lea    AuraSIntHandler(pc),a0
  245.         bra.s    sha_set
  246. sha_dual    tst.w    Auraratemode
  247.         beq.s    sha_d_var
  248.         lea    AuraFIntHandler(pc),a0
  249.         bra.s    sha_set
  250. sha_d_var    lea    AuraIntHandler(pc),a0
  251. sha_set        move.l    a0,Aurahandler
  252.         rts
  253.  
  254. ; SetAuraParams:
  255. ; D0 = flags:
  256. ;    bit 0:    0 = normal stereo/mono mode
  257. ;        1 = use only one channel (no stereo, slightly faster)
  258. ;    bit 1:    0 = use variable output rate
  259. ;        1 = locked output rate at max. period
  260. ; D1 = max. period
  261. _SetAuraParams:
  262.         move.w    d1,Auraratemode
  263.         btst    #0,d0
  264.         sne    Aurachmode+1
  265.         btst    #1,d0
  266.         sne    Auraratemode+1
  267.         rts
  268.